const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const dev = process.env.NODE_ENV !== 'production'
const config = {
  mode: dev ? 'development' : 'production',
  entry: './src/static/js/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
    publicPath: "http://localhost:8080/src"
  },
  module: {
    rules: [
      {
        test: /(\.js)$/,
        use: {
          loader: "babel-loader",
        },
        exclude: /node_modules/
      }
    ]
  },
  watch: true,
  devServer: {
    contentBase: './src',
    hot: true,
    inline: true
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(), //热加载插件
    new HtmlWebpackPlugin({template: './src/index.html'})
  ]
};

module.exports = config;
